﻿
using COVID_19_LiquidFillUI.ViewModels.Dialogs;
using COVID_19_LiquidFillUI.Views.Dialogs;
using System.Threading;
using System;
using COVID_19_LiquidFillUI.Views.Home;
using COVID_19_LiquidFillUI.ViewModels;
using COVID_19_LiquidFillUI.Common.Services;

namespace COVID_19_LiquidFillUI
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : PrismApplication
    {
        private static Mutex _mutex = null;
        protected override void OnStartup(StartupEventArgs e)
        {
            const string appName = "COVID-19-LiquidFillUI";
            bool createdNew;

            _mutex = new Mutex(true, appName, out createdNew);

            if (!createdNew)
            {
                MessageBox.Show("COVID-19-LiquidFillUI件已开启", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
                //app is already running! Exiting the application  
                Environment.Exit(-1);
            }

            base.OnStartup(e);
        }
        protected override Window CreateShell()
        {
            return Container.Resolve<MainWindow>();
        }

        protected override void RegisterTypes(IContainerRegistry containerRegistry)
        {
            containerRegistry.RegisterSingleton<ICameraService, CameraService>("Cam0");
            containerRegistry.RegisterSingleton<ICameraService, CameraService>("Cam1");
            containerRegistry.RegisterSingleton<ICameraService, CameraService>("Cam2");
            containerRegistry.RegisterSingleton<ICameraService, CameraService>("Cam3");
            containerRegistry.RegisterSingleton<IPLCModbusService, PLCModbusService>("plc");

            containerRegistry.RegisterForNavigation<Station1View, Station1ViewModel>("View1");
            containerRegistry.RegisterForNavigation<Station2View, Station2ViewModel>("View2");
            containerRegistry.RegisterDialog<Station1CameraCalcDialog, Station1CameraCalcDialogViewModel>();
            containerRegistry.RegisterDialog<Station2CameraCalcDialog, Station2CameraCalcDialogViewModel>();
        }
    }
}
